package com.hongfasoft.servlet;

import java.io.File;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jspsmart.upload.SmartUpload;

/**
 * 使用Jspsmart组件下载
 * 
 * @author mingxue.zhang@163.com
 * 
 */
@SuppressWarnings("serial")
public class JspsmartDownload extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SmartUpload smartUpload = new SmartUpload();
		request.setCharacterEncoding("UTF-8");
		smartUpload.initialize(this.getServletConfig(), request, response);
		smartUpload.setContentDisposition(null);
		System.out.println(request.getParameter("fileName"));
		@SuppressWarnings("unused")
		File downloadFile = new File(this.getServletContext().getRealPath("/") + "\\FileDir\\dirSmall" + "\\Oracle使用.txt");
//		List l = FileSystem.refreshFileList(this.getServletContext().getRealPath("/"));
		try {
			// smartUpload.downloadFile(downloadFile.getAbsolutePath());
			smartUpload.downloadFile(request.getParameter("fileName"));
			System.out.println("DownLoad success.");
//			if (l != null) {
//				for (int i = 0; i < l.size(); i++) {
//					String path = (String) l.get(i);
//					smartUpload.downloadFile(path);
//				}
//			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}
}
